package com.ruoyi.project.system.business.controller;

import java.util.List;

import com.ruoyi.common.utils.PageQuery;
import com.ruoyi.framework.web.page.TableData;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.business.domain.Business;
import com.ruoyi.project.system.business.service.IBusinessService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * businessController
 * 
 * @author ruoyi
 * @date 2024-07-18
 */
@Controller
@RequestMapping("/system/business")
public class BusinessController extends BaseController
{
    private String prefix = "system/business";

    @Autowired
    private IBusinessService businessService;

    @GetMapping()
    public String business()
    {
        return prefix + "/business";
    }

    /**
     * 查询business列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableData<Business> list(Business business, PageQuery pageQuery)
    {
        return businessService.selectBusinessList(business,pageQuery);
    }

    /**
     * 新增business
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存business
     */
    @Log(title = "business", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Business business)
    {
        return toAjax(businessService.insertBusiness(business));
    }

    /**
     * 修改business
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Business business = businessService.selectBusinessById(id);
        mmap.put("business", business);
        return prefix + "/edit";
    }

    /**
     * 修改保存business
     */
    @Log(title = "business", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Business business)
    {
        return toAjax(businessService.updateBusiness(business));
    }

    /**
     * 删除business
     */
    @Log(title = "business", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(businessService.deleteBusinessByIds(ids));
    }
}
